<%@codepage="65001"%>
<%session.codepage="65001"%>
<!-- #include virtual=/inc/dbConn.asp -->
<!-- #include virtual=/inc/function.asp -->
<!-- #include virtual=/inc/action.header.inc.asp -->

<%
	'## 파라미터 변수 선언부
	apprYear		= Request("apprYear")
	apprSeq		= Request("apprSeq")
	rcvrId			= Request("rcvrId")
	
	setUser	= Request("setUser")	'권한 위임
	
	if setUser = "" then 
		viewUser = Request.Cookies("S_uid")
	else 
		viewUser = setUser
	end if 
'	if setUser = "" then
		updateSql = "UPDATE tblWorkApprRcvr SET apprDt = getdate() WHERE apprDt IS NULL AND rcvrId='" & viewUser & "' AND apprType='R'"
		DbCon.Execute updateSql
'	end if 
	
	SQLTitle = "-- ■■■■  전자 결재 상세 정보 ■■■■"
	
	SQL = "SELECT B.userNm, A.apprYear, A.apprSeq, A.subjects, A.writeId, CONVERT(varchar(16), A.writeDt, 121) writeDt, CONVERT(varchar(16), A.modDt, 121) modDt, A.endDt, A.contents, A.files, A.flag " & _
			"	FROM tblWorkAppr A LEFT JOIN tblUser B ON A.writeId=B.userId WHERE A.apprYear='" & apprYear & "' AND A.apprSeq='" & apprSeq & "'"

	If xMode="debug" Then 
		Call showDebug(SQLTitle,SQL) 
	End If 

	Set Rs=Server.CreateObject("ADODB.RecordSet")
	Rs.open SQL, DbCon, 1
	
	Response.write "<WorkDetail>" & vbcrlf

	If Rs.eof Or Rs.bof Then 
	Else 
		Do Until Rs.eof Or Rs.bof
		
			Call mkXMLNode("apprYear", rs("apprYear"), 1)
			Call mkXMLNode("apprSeq", rs("apprSeq"), 1)
			Call mkXMLNode("userNm", rs("userNm"), 1)
			Call mkXMLNode("subjects", rs("subjects"), 1)
			Call mkXMLNode("writeDt", rs("writeDt"), 1)
			Call mkXMLNode("modDt", rs("modDt"), 1)
			Call mkXMLNode("endDt", rs("endDt"), 1)
			Call mkXMLNode("contents", rs("contents"), 1)
			Call mkXMLNode("writeId", rs("writeId"), 1)
			Call mkXMLNode("files", rs("files"), 1)
			Call mkXMLNode("flag", Rs("flag"), 1)
		Rs.movenext
		Loop 
	End If
	
	'## 수신자 정보 조회
	addSql = ""
'	if rcvrId <> "" and rcvrId <> "undefined" then
'		if setUser = "" then 
'			addSql = " AND A.rcvrId='" & rcvrId & "' "
'		else 
'			addSql = " AND A.rcvrId='" & setUser & "' "
'		end if  
'	end if 
	rcvrSql = "SELECT B.userNm, A.rcvrId, A.apprType, ISNULL(RIGHT(CONVERT(varchar(16), A.apprDt, 121),11),'') apprDt, A.allApprFlag, A.completeFlag, ISNULL(C.itemNm,'') dutyNm, " & _
				" 		CASE WHEN A.apprType='R' THEN '참조' WHEN A.apprFlag='Y' THEN '승인' WHEN A.apprFlag='N' THEN '반려' WHEN A.completeFlag='I' THEN '대기' ELSE '예정' END status " & _
				"	FROM tblWorkApprRcvr A LEFT JOIN tblUser B ON A.rcvrId=B.userID " & _
				"						LEFT JOIN (SELECT itemCd, itemNm FROM tblComCode WHERE groupCd='0007' AND flag='Y') C ON A.rcvrDuty=C.itemCd " & _
				"	WHERE A.apprYear='" & apprYear & "' AND A.apprSeq='" & apprSeq & "' " & addSql & _
				" 	ORDER BY A.rcvrSeq"
				
	If xMode="debug" Then 
		Call showDebug(SQLTitle & "수신자 정보",rcvrSql) 
	End If 

	Set rcvrRs=Server.CreateObject("ADODB.RecordSet")
	rcvrRs.open rcvrSql, DbCon, 1
	
	rcvrs = "<div style='float:left;width:25px;height:101px;border:1px #666 solid;font-weight:bold;margin-right:-2px;'><p style='text-align:center'>&nbsp; &nbsp; 결 &nbsp; &nbsp; 재</p></div>"
	If rcvrRs.eof Or rcvrRs.bof Then 
	Else 
		Do Until rcvrRs.eof Or rcvrRs.bof
			if rcvrRs("apprType") = "R" then 
				if refrs <> "" then refrs = refrs & ", "
				refrs = refrs & "<b>" & rcvrRs("userNm") & "</b>(" & rcvrRs("apprDt") & ")"
			else
				color = ""
				onClick = ""
				cursor = ""
				bgImg=""
				if rcvrRs("status") = "대기" then
					color = "background-color:#F2F2F2;"
					onClick =  "onClick=""fnApproval('" & apprYear & "','" & apprSeq & "','" & viewUser & "','" & rcvrRs("rcvrId") & "')"""
					cursor = "cursor:pointer;"
				elseif rcvrRs("status") = "승인" then
					bgImg = "background-image:url(/img/approved.jpg);background-repeat : no-repeat;"
				elseif rcvrRs("status") = "반려" then
					bgImg = "background-image:url(/img/denied.jpg);background-repeat : no-repeat;"
				end if 
				if rcvrRs("allApprFlag") = "A" then
					bgImg = "background-image:url(/img/all_approved.jpg);background-repeat : no-repeat;"
				end if 
				if rcvrRs("completeFlag") = "C" and rcvrRs("apprDt") = "" then
					bgImg = "background-image:url(/img/end.jpg);background-repeat : no-repeat;background-position: 1px 1px;"
				end if 
				if rcvrRs("dutyNm") <> "" then				
					userNm = rcvrRs("dutyNm") & " " & rcvrRs("userNm") 
				else
					userNm = rcvrRs("userNm")
				end if 
				rcvrs = rcvrs & "<div style='float:left;width:100px;height:101px;margin-left:1px;border:0;" & color & bgImg & "'>"
				rcvrs = rcvrs & "	<div style='width:100px;height:80px;border:1px #666 solid;font-size:13px;" & cursor & "' " & onClick & "><p style='padding-top:25px;color:#000;text-align:center;font-weight:bold;'>" & userNm & "</p></div>"
				rcvrs = rcvrs & "	<div style='width:100px;height:20px;border:1px #666 solid;margin-top:-1px;padding:0;'>" & rcvrRs("apprDt") & "</div>"
				rcvrs = rcvrs & "</div>" & vbcrlf
			end if 
		rcvrRs.movenext
		Loop 
	End If
	
		Call mkXMLNode("refrs", refrs, 1)
		Call mkXMLNode("rcvrs", rcvrs, 1)
		'Call mkXMLNode("status", status, 1)
				  
	Response.write "</WorkDetail>" & vbcrlf
'	Call rsWithXML("Save OK!")
%>